import { BSDataTypeEnum, RecordTypeEnum } from "@@/constants/other-keys"
import { ElInput } from "element-plus"
import { VxeUI } from "vxe-pc-ui"
import EnumValueDownModal from "./EnumValueDownModal.vue"
import TypingValueBfModal from "./TypingValueBfModal.vue"
import TypingValueDownModal from "./TypingValueDownModal.vue"

// 创建一个复杂的组合渲染
VxeUI.renderer.add("TypingValueBfModal", {
  tableAutoFocus: "input",
  renderTableDefault(renderOpts, params) {
    const { row, column } = params
    row.typeId = row.field.typeId
    row.code = row.field.code

    if (row.field) {
      row.type = row.field && row.field.type
      row.recordType = row.field && row.field.recordType
    }

    let renderInner = <ElInput v-model={row[column.field]} />
    if (row.field.type === BSDataTypeEnum.Base) {
      renderInner = <ElInput v-model={row[column.field]} />
    }
    if (row.field.type === BSDataTypeEnum.Enum) {
      // ……务必设置，便于枚举值选择统一处理
      row.typeId = row.field.typeId
      row.typeCode = row.field.typeCode
      if (row.field.recordType == RecordTypeEnum.Base) {
        renderInner = <EnumValueDownModal params={params} renderOpts={renderOpts} />
      } else {
        renderInner = <TypingValueBfModal params={params} renderOpts={renderOpts} />
      }
    }
    if (row.field.type === BSDataTypeEnum.Class) {
      // ……务必设置，便于枚举值选择统一处理
      row.typeId = row.field.typeId
      row.typeCode = row.field.typeCode
      if (row.field.recordType == RecordTypeEnum.Base) {
        renderInner = (
          <TypingValueDownModal
            params={params}
            renderOpts={renderOpts}
          />
        )
      } else {
        renderInner = (
          <TypingValueBfModal
            params={params}
            renderOpts={renderOpts}
          >
          </TypingValueBfModal>
        )
      }
    }
    return renderInner
  }
})
